package com.itheima.supermarket.manage.dao;

import com.itheima.supermarket.manage.domain.Managers;

import java.io.*;
import java.util.ArrayList;

public class ManagerDao {

    //获取文件中的账号密码集合
    public ArrayList<Managers> getManagers() throws IOException {
        ArrayList<Managers> managers = new ArrayList<>();
        BufferedReader br = new BufferedReader(new FileReader("Fruit\\txt\\Managers.txt"));
        String line;
        while ((line = br.readLine()) != null) {
            String[] split = line.split(",");
            Managers m = new Managers(split[0],split[1]);
            managers.add(m);
        }
        return managers;
    }

    //添加注册管理员信息
    public synchronized void addRegister(String userName, String passWord) throws IOException {
        BufferedWriter bw = new BufferedWriter(new FileWriter("Fruit\\txt\\Managers.txt",true));
        String s = userName + "," + passWord;
        bw.write(s);
        bw.newLine();
        bw.close();
    }
}
